package org.study.seatatcc.stock.service;

import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.seata.rm.tcc.api.*;
import org.study.seatatcc.stock.entity.Stock;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2024年01月25日
 */
@LocalTCC
public interface StockService extends IService<Stock> {
    /**
     * 减库存
     */
    @TwoPhaseBusinessAction(name = "deduct", commitMethod = "busCommit", rollbackMethod = "busRollback", useTCCFence = true)
    void deduct(@BusinessActionContextParameter(paramName = "commodityCode") String commodityCode,
                @BusinessActionContextParameter(paramName = "count") int count);

    /**
     * 减库存：提交事务
     */
    boolean busCommit(BusinessActionContext actionContext);

    /**
     * 减库存：回滚事务
     */
    boolean busRollback(BusinessActionContext actionContext);
}
